@extends('layouts.default')
@section('main')
    <link rel="stylesheet" href="/css/uniform.css"/>
    <link rel="stylesheet" href="/css/select2.css"/>
    <script src="{{URL::asset('js/My97DatePicker/')}}/WdatePicker.js"></script>
    <script type="text/javascript" src="{{URL::asset('js/')}}/jquery-1.8.3.min.js"></script>

    <div id="content">
        <div id="content-header">
            <div id="breadcrumb">
                <a href="{{url('home')}}" title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a>
            </div>
        </div>
        <div class="container-fluid">
            <div class="widget-title">
                <ul class="nav nav-tabs">
                    {{--<li class="active"><a data-toggle="tab" href="#tab1">发布数</a></li>--}}
                    {{--<li><a data-toggle="tab" href="#tab2">文章总点击量</a></li>--}}
                    <li class="active"><a data-toggle="tab" href="#tab3">数据表</a></li>
                </ul>
            </div>
            <div class="widget-content tab-content">


                <div id="tab3" class="tab-pane active">

                    <form action="{{url('projectstatistic/export')}}" id="adForm" method="get">
                        <table>
                            <tr>
                                <th>
                                    <label>类型 :</label>
                                </th>
                                <th>
                                    <div class="controls">
                                        <select name="type">
                                            <option value="">请选择</option>
                                            <option value="pub">发布数据</option>
                                            <option value="show_apply">路演申请</option>
                                            <option value="show_success">路演成功</option>
                                        </select>
                                    </div>
                                </th>
                                <th>
                                    <label>开始时间 :</label>
                                </th>
                                <th>
                                    <div class="controls">
                                        <input type="text" name="begin_time"
                                               placeholder="开始时间" onfocus="WdatePicker({startDate:'%y-%M-01 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})"/>
                                    </div>
                                </th>
                                <th>
                                    <label>结束时间 :</label>
                                </th>
                                <th>
                                    <div class="controls">
                                        <input type="text" name="end_time"
                                               placeholder="结束时间" onfocus="WdatePicker({startDate:'%y-%M-01 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})"/>
                                    </div>
                                </th>
                                <th>
                                    <input type="hidden" name="_token" value="{{ csrf_token() }}">

                                    <div class="controls">
                                        <button type="button" name="find" class="btn btn-info">查询</button>
                                        <button type="submit" class="btn btn-info">导出</button>
                                    </div>
                                </th>
                            </tr>
                        </table>
                    </form>

                    <div id="result">
                    </div>
                    <div id="ajaxPage">
                    </div>

                </div>
            </div>
        </div>


    </div>
    <script src="/js/matrix.tables.js"></script>
    <script type="text/javascript" src="{{URL::asset('js/')}}/common.js"></script>

    <script>

        //异步获取
        $('button[name=find]').click(function () {
            ajaxRequest($('#adForm').serializeArray(), "/projectstatistic/query", function (data) {
                if (data.status) {
                    var html = '<table class="table table-bordered table-striped">';

                    if ('pub' == data.message.type) {
                        html += '<thead>';
                        html += '<tr>';
                        html += '<th>项目名称</th>';
                        html += '<th>地区</th>';
                        html += '<th>发布时间</th>';
                        html += '<th>类型</th>';
                        html += '<th>项目详情</th>';
                        html += '</tr>';
                        html += '</thead>';
                        html += '<tbody>';
                        $.each(data.message.list, function (i, e) {
                            html += '<tr class="gradeX">';
                            html += '<td>' + e.subject + '</td>';
                            html += '<td>' + e.zone + '</td>';
                            html += '<td>' + e.created_at + '</td>';
                            html += '<td>' + e.type + '</td>';
                            html += '<td><a href="/project/info?id=' + e.id + '">点击查看</a></td>';
                            html += '<tr>';
                        });
                    } else if('show_apply' == data.message.type) {
                        html += '<thead>';
                        html += '<tr>';
                        html += '<th>申请人</th>';
                        html += '<th>发起类型</th>';
                        html += '<th>空间名</th>';
                        html += '<th>申请时间</th>';
                        html += '</tr>';
                        html += '</thead>';
                        html += '<tbody>';
                        $.each(data.message.list, function (i, e) {
                            html += '<tr class="gradeX">';
                            html += '<td>' + e.username + '</td>';
                            html += '<td>' + e.initiator + '</td>';
                            html += '<td>' + e.maker_name + '</td>';
                            html += '<td>' + e.created_at + '</td>';
                            html += '<tr>';
                        });
                    }else{
                        html += '<thead>';
                        html += '<tr>';
                        html += '<th>项目名</th>';
                        html += '<th>活动名</th>';
                        html += '<th>路演时间</th>';
                        html += '</tr>';
                        html += '</thead>';
                        html += '<tbody>';
                        $.each(data.message.list, function (i, e) {
                            html += '<tr class="gradeX">';
                            html += '<td>' + e.project_name + '</td>';
                            html += '<td>' + e.activity_name + '</td>';
                            html += '<td>' + e.created_at + '</td>';
                            html += '<tr>';
                        });
                    }

                    $("#ajaxPage").html(data.message.page);
                    $("#result").html(html);
                } else {
                    alert(data.message);
                }
            });
        });

        /*
         * 异步分页
         */
        $("body").on('click', '#ajaxPage li', function () {
            if (!$(this).hasClass('pagemore')) {
                var page = $(this).attr('value');
                var params = {};
                params['page'] = page;
                params['begin_time'] = $("input[name='begin_time']").val();
                params['end_time'] = $('input[name=end_time]').val();
                params['type'] = $("select[name=type]").val();
                if (page == 0) {
                    return false;
                }
                ajaxRequest(params, "/projectstatistic/query", function (data) {
                    if (data.status) {
                        var html = '<table class="table table-bordered table-striped">';

                        if ('pub' == data.message.type) {
                            html += '<thead>';
                            html += '<tr>';
                            html += '<th>项目名称</th>';
                            html += '<th>地区</th>';
                            html += '<th>发布时间</th>';
                            html += '<th>类型</th>';
                            html += '<th>项目详情</th>';
                            html += '</tr>';
                            html += '</thead>';
                            html += '<tbody>';
                            $.each(data.message.list, function (i, e) {
                                html += '<tr class="gradeX">';
                                html += '<td>' + e.subject + '</td>';
                                html += '<td>' + e.zone + '</td>';
                                html += '<td>' + e.created_at + '</td>';
                                html += '<td>' + e.type + '</td>';
                                html += '<td><a href="/project/info?id=' + e.id + '">点击查看</a></td>';
                                html += '<tr>';
                            });
                        } else if('show_apply' == data.message.type) {
                            html += '<thead>';
                            html += '<tr>';
                            html += '<th>申请人</th>';
                            html += '<th>发起类型</th>';
                            html += '<th>空间名</th>';
                            html += '<th>申请时间</th>';
                            html += '</tr>';
                            html += '</thead>';
                            html += '<tbody>';
                            $.each(data.message.list, function (i, e) {
                                html += '<tr class="gradeX">';
                                html += '<td>' + e.username + '</td>';
                                html += '<td>' + e.initiator + '</td>';
                                html += '<td>' + e.maker_name + '</td>';
                                html += '<td>' + e.created_at + '</td>';
                                html += '<tr>';
                            });
                        }else{
                            html += '<thead>';
                            html += '<tr>';
                            html += '<th>项目名</th>';
                            html += '<th>活动名</th>';
                            html += '<th>路演时间</th>';
                            html += '</tr>';
                            html += '</thead>';
                            html += '<tbody>';
                            $.each(data.message.list, function (i, e) {
                                html += '<tr class="gradeX">';
                                html += '<td>' + e.project_name + '</td>';
                                html += '<td>' + e.activity_name + '</td>';
                                html += '<td>' + e.created_at + '</td>';
                                html += '<tr>';
                            });
                        }

                        $("#ajaxPage").html(data.message.page);
                        $("#result").html(html);
                    } else {
                        alert(data.message);
                    }
                });
            }
        });


        //跳转分页
        $("#ajaxPage").on('click', '.ajaxPagegoto', function () {
            var page = $(".page-num").val();
            var params = {};
            params['page'] = page;
            params['begin_time'] = $('input[name=begin_time]').val();
            params['end_time'] = $('input[name=end_time]').val();
            params['type'] = $('select[name=type').val();
            if (page == undefined) {
                showMessage("error", '请输入正确的跳转页数');
            } else {
                var lastpage = $("#ajaxPage .lastpage").attr('value');
                if (parseInt(page) > parseInt(lastpage)) {
                    page = lastpage;
                }
                ajaxRequest(params, '/userstatistic/query', function (data) {
                    if (data.status) {
                        var html = '<table class="table table-bordered table-striped">';

                        if ('pub' == data.message.type) {
                            html += '<thead>';
                            html += '<tr>';
                            html += '<th>项目名称</th>';
                            html += '<th>地区</th>';
                            html += '<th>发布时间</th>';
                            html += '<th>类型</th>';
                            html += '<th>项目详情</th>';
                            html += '</tr>';
                            html += '</thead>';
                            html += '<tbody>';
                            $.each(data.message.list, function (i, e) {
                                html += '<tr class="gradeX">';
                                html += '<td>' + e.subject + '</td>';
                                html += '<td>' + e.zone.name + '</td>';
                                html += '<td>' + e.created_at + '</td>';
                                html += '<td>' + e.type + '</td>';
                                html += '<td><a href="/project/info?id=' + e.id + '">点击查看</a></td>';
                                html += '<tr>';
                            });
                        } else if('show_apply' == data.message.type) {
                            html += '<thead>';
                            html += '<tr>';
                            html += '<th>申请人</th>';
                            html += '<th>发起类型</th>';
                            html += '<th>空间名</th>';
                            html += '<th>申请时间</th>';
                            html += '</tr>';
                            html += '</thead>';
                            html += '<tbody>';
                            $.each(data.message.list, function (i, e) {
                                html += '<tr class="gradeX">';
                                html += '<td>' + e.username + '</td>';
                                html += '<td>' + e.initiator + '</td>';
                                html += '<td>' + e.maker_name + '</td>';
                                html += '<td>' + e.created_at + '</td>';
                                html += '<tr>';
                            });
                        }else{
                            html += '<thead>';
                            html += '<tr>';
                            html += '<th>项目名</th>';
                            html += '<th>活动名</th>';
                            html += '<th>路演时间</th>';
                            html += '</tr>';
                            html += '</thead>';
                            html += '<tbody>';
                            $.each(data.message.list, function (i, e) {
                                html += '<tr class="gradeX">';
                                html += '<td>' + e.project_name + '</td>';
                                html += '<td>' + e.activity_name + '</td>';
                                html += '<td>' + e.created_at + '</td>';
                                html += '<tr>';
                            });
                        }

                        $("#ajaxPage").html(data.message.page);
                        $("#result").html(html);
                    } else {
                        alert(data.message);
                    }
                });
            }
        });

    </script>

@stop
